#include "CorePch.h"
#include "JTime.h"
#include <sys/types.h>
#include <sys/timeb.h>

namespace JJc
{
	JJcTime::JJcTime()
	{
		m_timeb = (__timeb64*)malloc(sizeof(__timeb64));
		ASSERT(m_timeb);
		_ftime64(m_timeb);
	}


	//************************************
	// Method:    GetTime
	// Author:    J.J. WANG
	// Description: return milliseconds since SetTime() called, if SetTime() did not call since when JJcTime created.
	//************************************
	int64 JJcTime::GetTime()	
	{
		__timeb64 currtime;
		_ftime64(&currtime);
		elapsedSecond = currtime.time - m_timeb->time;
		elapsedMilliSecond =currtime.millitm - m_timeb->millitm;
		if(elapsedMilliSecond<0 )
		{
			elapsedMilliSecond+=1000;
			elapsedSecond--;
		}
		return elapsedSecond*1000 + elapsedMilliSecond;
	}

	void JJcTime::SetTime()
	{
		_ftime64(m_timeb);
	}
	
}